<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * @classname Categories
 *
 * @package	Package Name
 * @subpackage	Subpackage
 * @category	Category
 * @author	Ones Lynxs / 
 * @email ones006@gmail.com
 * @link	http://oemahcode.com
 * created 
 */

class Categories extends OC_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('articles/category_model','cm');
	}

	function _remap($method, $params = array())
	{
		parent::_remap($method, $params);
		
		if (method_exists($this, $method))
			return call_user_func_array(array($this, $method), $params);
		else
			show_404();
	}

	function init_header()
	{
		$this->header['jeasyui'] = TRUE;
		$this->header['source_bot'] = array(
			script_tag(site_url('articles/themescript/app/article_category.js'))
		);
	}

	function index()
	{
		$this->init_header();
		$this->header['nav'] = 'articles';
		$this->header['pagetitle'] = 'Article Categories';
		$this->view('articles/categories_view');
	}

	function load_data()
	{
		$params = $this->input->post();
		$result = $this->cm->get_all($params);
		print(json_encode($result));
	}

	function save_data()
	{
		$post = $this->input->post();
		
		if (empty($post['ca_id']))
		{
			$post['ca_created_date']  = date('Y-m-d H:i:s');
			unset($post['ca_id']);
			$this->cm->add($post);
		}
		else
		{
			$post['ca_modified_date']  = date('Y-m-d H:i:s');
			$this->cm->edit($post, array('ca_id' => $post['ca_id']));
		}

		print(json_encode(array(
			'success' => TRUE
		)));
	}

	function delete_data()
	{
		$post = $this->input->post();
		$this->cm->delete(array('ca_id' => $post['ca_id']));
		print(json_encode(array(
			'success' => TRUE
		)));
	}

}

/* End of file categories.php */
/* Location: ./applications/module_admin/articles/controllers/categories.php */